package com.yunji.base.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yunji.base.dao.ISiteScaleDao;
import com.yunji.base.domain.SiteScaleDO;
import com.yunji.base.mapper.ISiteScaleMapper;
import com.yunji.base.vo.SiteScaleVO;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/11/7 20:03
 * @description : TODO
 **/
@Repository
public class SiteScaleDaoImpl extends BaseDaoImpl<ISiteScaleMapper, SiteScaleDO> implements ISiteScaleDao {
    @Override
    public List<SiteScaleDO> search(SiteScaleDO scaleDO) {
        return list(new LambdaQueryWrapper<SiteScaleDO>()
                .eq(BeanUtils.isNotNull(scaleDO.getSiteId()), SiteScaleDO::getSiteId, scaleDO.getSiteId())
                .eq(BeanUtils.isNotNull(scaleDO.getAuditId()), SiteScaleDO::getAuditId, scaleDO.getAuditId()));
    }

    @Override
    public void deleteBySiteId(Long siteId) {
        LambdaQueryWrapper<SiteScaleDO> queryWrapper = new LambdaQueryWrapper<>();
        remove(queryWrapper.eq(SiteScaleDO::getSiteId, siteId));
    }

    @Override
    public List<SiteScaleDO> getByAuditId(Long auditId) {
        return list(new LambdaQueryWrapper<SiteScaleDO>().eq(SiteScaleDO::getAuditId, auditId));
    }

    @Override
    public List<SiteScaleDO> listScaleBySiteIds(List<Long> siteIds) {
        return lambdaQuery().in(SiteScaleDO::getSiteId, siteIds).list();
    }

    @Override
    public List<SiteScaleDO> listBySiteId(Long siteId) {
        return lambdaQuery().eq(SiteScaleDO::getSiteId, siteId).list();
    }

    @Override
    public void setSiteIdByAuditId(Long siteId,Long auditId) {
        baseMapper.update(new LambdaUpdateWrapper<SiteScaleDO>()
                .set(SiteScaleDO::getSiteId,siteId)
                .eq(SiteScaleDO::getAuditId,auditId));
    }

    @Override
    public void deleteByAuditId(Long auditId) {
        remove(new LambdaQueryWrapper<SiteScaleDO>().eq(SiteScaleDO::getAuditId, auditId));
    }

}
